//
//  AddOrderTableViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/5/12.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "AddOrderTableViewCell.h"

@interface AddOrderTableViewCell()

@property (nonatomic,strong) UIImageView *imgView;
@property (nonatomic,strong) UILabel *infoLabel;
@property (nonatomic,strong) UIView *bgView;

@end

@implementation AddOrderTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        self.contentView.backgroundColor = getColor(@"f1f2f6");
        
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
        
        _imgView = [UIImageView new];
        _imgView.backgroundColor = getColor(@"f1f2f6");
        _imgView.contentMode = UIViewContentModeScaleAspectFill;
        _imgView.layer.masksToBounds = YES;
        
        _infoLabel = [UILabel new];
        _infoLabel.numberOfLines = 0;
        _infoLabel.font = DEF_FontSize_11;
        
        [self.contentView addSubview:self.bgView];
        
        [self.bgView addSubview:_imgView];
        [self.bgView addSubview:_infoLabel];
    }
    
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    _bgView.frame = CGRectMake(0, 5, SCREEN_WIDTH, self.height-5);
    _imgView.frame = CGRectMake(12, 0, self.frame.size.height-15, self.frame.size.height-15);
    _imgView.center = CGPointMake(_imgView.center.x, (self.frame.size.height-5)/2.);
    
    _infoLabel.frame = CGRectMake(CGRectGetMaxX(_imgView.frame)+10, 0, SCREEN_WIDTH - CGRectGetMaxX(_imgView.frame) - 60, self.frame.size.height-5);
}

- (void)setDataDictionary:(NSDictionary *)dataDictionary{
    _dataDictionary = dataDictionary;
    [_imgView sd_setImageWithURL:[NSURL URLOffsetIPWithString:dataDictionary[@"c_first_figure"]]];
    
    NSString *title = dataDictionary[@"c_name"];
    NSString *info = dataDictionary[@"ocl_num"];
    NSString *price = dataDictionary[@"c_unit_price"];
    NSString *temp = [NSString stringWithFormat:@"%@\n数量 %@\n价格¥ %@",title,info,price];
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:temp];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:4];//调整行间距
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [temp length])];
    
    _infoLabel.attributedText = attStr;
    
}

@end
